import {
  ProFormDigit,
  ProTable,
  ProFormDependency,
} from '@ant-design/pro-components';
import {
  Button,
  Popconfirm,
  message,
  Tag,
  Upload,
  Table,
  Space,
  Breadcrumb,
  Select,
} from 'antd';
import { PageContainer } from '@ant-design/pro-layout';
import { useRequest } from 'umi';
import type { UploadProps } from 'antd';
import { UploadOutlined, FileSearchOutlined } from '@ant-design/icons';
import type { ProFormInstance } from '@ant-design/pro-components';
import ImportExcel from '@/pages/LabManage/component/ImportExcel';
import { useBoolean } from 'ahooks';
import {
  ModalForm,
  ProForm,
  ProFormSelect,
  ProFormText,
  ProFormDatePicker,
  ProFormTextArea,
} from '@ant-design/pro-components';
import moment from 'moment';
import ReturnTablist from '@/components/TabList';
import React, { useEffect, useRef, useState } from 'react';
import SearchByRole from '@/components/SearchByRole';

export default () => {
  const formRef = useRef<ProFormInstance>();
  const editformRef = useRef<ProFormInstance>();
  const [selectRow, { toggle }] = useBoolean(false);
  const [tabKey, setTabKey] = useState('个人视角');
  const ref = useRef<ProFormInstance>();
  const { Option } = Select;

  const updateStatus = useRequest(
    (data = {}) => {
      return {
        url: 'http://10.1.40.84:9993/common/updateStatus',
        method: 'POST',
        headers: {
          Authorization: localStorage.getItem('token') || '',
        },
        data,
      };
    },
    {
      manual: true,
    },
  );

  const props: UploadProps = {
    name: 'file',
    action: 'http://10.1.40.84:9993/common/uploadFile',
    headers: {
      Authorization: localStorage.getItem('token') || '',
    },
    maxCount: 1,
    onChange(info) {
      if (info.file.status !== 'uploading') {
        console.log(info.file, info.fileList);
      }
      if (info.file.status === 'done') {
        formRef.current?.setFieldsValue({ annexPath: info.file.response.data });
        editformRef.current?.setFieldsValue({
          annexPath: info.file.response.data,
        });
        message.success(`${info.file.name} 上传成功！`);
      } else if (info.file.status === 'error') {
        message.error(`${info.file.name} file upload failed.`);
      }
    },
  };

  //获取 会议 列表
  const findAllHostUnderMeeting = useRequest((data = { auth: 0 }) => {
    return {
      url: `http://10.1.40.84:9993/hostUnderMeeting/findAllHostUnderMeeting`,
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data,
    };
  });
  //新增 会议
  const insertHostUnderMeeting = useRequest(
    (data = undefined) => {
      return {
        url: `http://10.1.40.84:9993/hostUnderMeeting/insertHostUnderMeeting`,
        method: 'POST',
        headers: {
          Authorization: localStorage.getItem('token') || '',
        },
        data,
      };
    },
    {
      manual: true,
    },
  );
  //删除 会议
  const delHostUnderMeeting = useRequest(
    (data = undefined) => {
      return {
        url: `http://10.1.40.84:9993/hostUnderMeeting/delHostUnderMeeting`,
        method: 'POST',
        headers: {
          Authorization: localStorage.getItem('token') || '',
        },
        data,
      };
    },
    {
      manual: true,
    },
  );
  //编辑 会议
  const updateHostUnderMeeting = useRequest(
    (data = undefined) => {
      return {
        url: `http://10.1.40.84:9993/hostUnderMeeting/updateHostUnderMeeting`,
        method: 'POST',
        headers: {
          Authorization: localStorage.getItem('token') || '',
        },
        data,
      };
    },
    {
      manual: true,
    },
  );

  const getLike = useRequest((data = { field: 'country' }) => {
    return {
      url: 'http://10.1.40.84:9993/getLike',
      method: 'POST',
      headers: {
        Authorization: localStorage.getItem('token') || '',
      },
      data,
    };
  });
  const getLike2 = useRequest(
    (data = {}) => {
      return {
        url: 'http://10.1.40.84:9993/getLike',
        method: 'POST',
        headers: {
          Authorization: localStorage.getItem('token') || '',
        },
        data,
      };
    },
    {
      manual: true,
    },
  );
  const getCity = useRequest(
    (data = { field: 'CITY', key: '' }) => {
      return {
        url: 'http://10.1.40.84:9993/getLike',
        method: 'POST',
        headers: {
          Authorization: localStorage.getItem('token') || '',
        },
        data,
      };
    },
    {
      manual: true,
    },
  );
  const getProvince = useRequest(
    (data = { field: 'PROVINCE', key: '' }) => {
      return {
        url: 'http://10.1.40.84:9993/getLike',
        method: 'POST',
        headers: {
          Authorization: localStorage.getItem('token') || '',
        },
        data,
      };
    },
    {
      manual: true,
    },
  );

  const confirm = (e: any) => {
    delHostUnderMeeting.run({ id: e.id }).then(() => {
      findAllHostUnderMeeting.run({ auth: authAdapter(tabKey) });
      message.success('删除成功');
    });
  };
  const cancel = (e: any) => {
    message.error('已取消');
  };
  const columns: any = [
    {
      title: '人员',
      align: "center",
      key: 'userId',
      dataIndex: 'userId',
      hideInTable: true,
      hideInSearch: tabKey === '个人视角',
      renderFormItem: () => {
        return (
          <Select
            showSearch
            filterOption={(input, option) =>
              (option!.children as unknown as string)
                .toLowerCase()
                .includes(input.toLowerCase())
            }
          >
            {SearchByRole(tabKey)?.people?.map((item: any) => (
              <Option key={item.value} value={item.value}>
                {item.label}
              </Option>
            ))}
          </Select>
        );
      },
    },
    {
      title: '子方向',
      align: "center",
      dataIndex: 'groupId',
      key: 'groupId',
      hideInTable: true,
      hideInSearch: tabKey === '个人视角' || tabKey === '子方向视角',
      renderFormItem: () => {
        return (
          <Select
            showSearch
            filterOption={(input, option) =>
              (option!.children as unknown as string)
                .toLowerCase()
                .includes(input.toLowerCase())
            }
          >
            {SearchByRole(tabKey)?.team?.map((item: any) => (
              <Option key={item.value} value={item.value}>
                {item.label}
              </Option>
            ))}
          </Select>
        );
      },
    },
    {
      title: '方向',
      align: "center",
      dataIndex: 'directionId',
      key: 'directionId',
      hideInTable: true,
      hideInSearch: tabKey !== '管理员视角',
      renderFormItem: () => {
        return (
          <Select
            showSearch
            filterOption={(input, option) =>
              (option!.children as unknown as string)
                .toLowerCase()
                .includes(input.toLowerCase())
            }
          >
            {SearchByRole(tabKey)?.direction?.map((item: any) => (
              <Option key={item.value} value={item.value}>
                {item.label}
              </Option>
            ))}
          </Select>
        );
      },
    },
    {
      title: '序号',
      align: "center",
      dataIndex: 'seq',
      key: 'seq',
      // copyable: true,
      hideInSearch: true,
      width: 50,
      hideInTable: localStorage.getItem('identity') !== '管理员',
    },
    {
      title: '会议年份',
      align: "center",
      dataIndex: 'year',
      key: 'year',
      valueType: 'dateYear',
      hideInSearch: localStorage.getItem('identity') !== '管理员',
      hideInTable: localStorage.getItem('identity') !== '管理员',
      render: (text: any, record: any, index: any) => {
        return record?.year ? moment(record?.year + '').format('YYYY') : null;
      },
      sorter: {
        compare: (a, b) => a.year - b.year,
      },
    },
    {
      title: '会议名称',
      align: "center",
      dataIndex: 'meetName',
      key: 'meetName',
      // width: 200,
      // copyable: true,
      // ellipsis: true,
    },
    {
      title: '会议主席',
      align: "center",
      dataIndex: 'meetLeader',
      key: 'meetLeader',
      // width: 130,
      hideInSearch: true,
    },
    {
      title: '会议执行主席',
      align: "center",
      dataIndex: 'meetImpleLeader',
      key: 'meetImpleLeader',
      // width: 100,
      hideInSearch: true,
    },
    {
      title: '举办类型',
      align: "center",
      dataIndex: 'holdType',
      key: 'holdType',
      // width: 100,
      hideInSearch: true,
    },
    {
      title: '会议类型',
      align: "center",
      dataIndex: 'meetType',
      key: 'meetType',
      // width: 100,
      hideInSearch: true,
    },
    {
      title: '参会人数',
      align: "center",
      dataIndex: 'peopleCount',
      key: 'peopleCount',
      // width: 100,
      hideInSearch: true,
    },
    {
      title: '会议日期',
      align: "center",
      dataIndex: 'startTime',
      key: 'startTime',
      // width: 120,
      hideInSearch: true,
    },
    {
      title: '国别',
      align: "center",
      dataIndex: 'meetPlace',
      key: 'meetPlace',
      hideInSearch: true,
    },
    {
      title: '国家',
      align: "center",
      dataIndex: 'country',
      key: 'country',
      hideInSearch: true,
    },
    {
      title: '省',
      align: "center",
      dataIndex: 'province',
      key: 'province',
      hideInSearch: true,
    },
    {
      title: '市',
      align: "center",
      dataIndex: 'city',
      key: 'city',
      hideInSearch: true,
    },
    {
      title: '报道链接',
      align: "center",
      dataIndex: 'reportLink',
      key: 'reportLink',
      hideInSearch: true,
      render: (text: any, record: any) => {
        if (record.reportLink !== null) {
          return (
            <a
              onClick={() => {
                window.open(text);
              }}
            >
              查看链接
            </a>
          );
        } else {
          return <span>暂无链接</span>;
        }
      },
    },
    {
      title: '材料',
      align: "center",
      dataIndex: 'annexPath',
      key: 'annexPath',
      hideInSearch: true,
      render: (text: any, record: any) => {
        if (record.annexPath !== null) {
          return (
            <a
              onClick={() => {
                window.open(text);
              }}
            >
              下载
            </a>
          );
        } else {
          return <span>暂无材料</span>;
        }
      },
    },
    {
      title: '状态',
      align: "center",
      key: 'finalStr',
      dataIndex: 'finalStr',
      hideInSearch: true,
      filters: true,
      onFilter: true,
      valueType: 'select',
      valueEnum: {
        未提交: { text: '未提交' },
        待上传文件: {
          text: '待上传文件',
        },
        待用户修改: {
          text: '待用户修改',
        },
        待子方向负责人审核: {
          text: '待子方向负责人审核',
        },
        待子方向负责人确认: {
          text: '待子方向负责人确认',
        },
        待管理员审核: {
          text: '待管理员审核',
        },
      },
    },
    {
      title: '操作',
      align: "center",
      key: 'option',
      width: '13%',
      fixed: 'right',
      valueType: 'option',
      render: (text: any, record: any) => {
        let optionName: any = '';
        let singleRefuseShow: boolean = false;
        let singleRefuseDisabled: boolean = true;

        if (tabKey === '管理员视角') {
          if (record.finalStr === '待管理员审核') {
            singleRefuseDisabled = false;
            optionName = '修改';
          } else {
            optionName = '查看';
          }
        } else {
          if (tabKey === '子方向视角') {
            if (record.finalStr === '待子方向负责人审核') {
              optionName = '修改';
              singleRefuseDisabled = false;
            } else if (record.finalStr === '待子方向负责人确认') {
              optionName = '审核';
            } else {
              optionName = '查看';
            }
          }
          if (tabKey === '方向视角') {
            optionName = '查看';
            singleRefuseShow = true;
          }
          if (tabKey === '个人视角') {
            singleRefuseShow = true;
            if (record.finalStr === '未提交') {
              optionName = '继续填写';
            } else if (
              record.finalStr === '待用户修改' ||
              record.finalStr === '待上传文件'
            ) {
              optionName = '修改';
            } else {
              optionName = '查看';
            }
          }
        }
        let deleteHidden: boolean = true;
        if (tabKey === '管理员视角') {
          deleteHidden = false;
        } else {
          if (
            record.finalStr === '待子方向负责人审核' ||
            record.finalStr === '未提交' ||
            record.finalStr === '待上传文件'
          ) {
            deleteHidden = false;
          }
        }
        return (
          <Space>
            <ModalForm
              title={
                record?.message ? (
                  <div>
                    {optionName}{' '}
                    <span style={{ color: 'red', textAlign: 'center' }}>
                      {'(拒绝原因：' + record?.message + ')'}
                    </span>{' '}
                  </div>
                ) : (
                  optionName
                )
              }
              trigger={<a> {optionName}</a>}
              autoFocusFirstInput
              modalProps={{
                onCancel: () => console.log('run'),
                destroyOnClose: true,
              }}
              submitTimeout={2000}
              onFinish={async (values) => {
                if (optionName !== '审核') {
                  updateHostUnderMeeting.run(values).then(() => {
                    findAllHostUnderMeeting.run({ auth: authAdapter(tabKey) });
                  });
                } else {
                  if (values?.annexPath) {
                    if (values.sumbitType === '提交管理员审核') {
                      updateHostUnderMeeting.run(values).then(() => {
                        updateStatus
                          .run({
                            tableName: 'HOST_UNDER_MEETING',
                            ids: [record.id],
                            status: 2, //审核通过
                            tab: '子方向视角',
                          })
                          .then(() => {
                            findAllHostUnderMeeting.run({
                              auth: authAdapter(tabKey),
                            });
                            message.success('操作成功');
                          });
                      });
                    } else if (values.sumbitType === '返回成员修改') {
                      return true;
                    }
                  } else {
                    message.warning('缺少文件！');
                  }
                }
                // updateHostUnderMeeting.run(values).then(() => {
                //   message.info('编辑成功！');
                //   findAllHostUnderMeeting.run();
                // });
                return true;
              }}
              initialValues={
                record?.year ? record : { ...record, year: undefined }
              }
              key="1"
              grid={true}
              formRef={editformRef}
              submitter={{
                render: (props, doms) => {
                  if (optionName === '审核') {
                    return [
                      <ModalForm
                        key="ModalForm"
                        title="返回成员修改"
                        trigger={
                          <Button
                            key="2"
                            onClick={() => {
                              editformRef.current?.setFieldsValue({
                                sumbitType: '返回成员修改',
                              });
                            }}
                          >
                            返回成员修改
                          </Button>
                        }
                        autoFocusFirstInput
                        modalProps={{
                          onCancel: () => console.log('run'),
                          destroyOnClose: true,
                        }}
                        submitTimeout={2000}
                        onFinish={async (values) => {
                          console.log(values);
                          updateStatus
                            .run({
                              tableName: 'HOST_UNDER_MEETING',
                              ids: [record.id],
                              status: 3, //拒绝
                              message: values.message,
                              tab: '子方向视角',
                            })
                            .then(() => {
                              findAllHostUnderMeeting.run({
                                auth: authAdapter(tabKey),
                              });
                              message.success('操作成功');
                            });
                          props.form?.submit();
                          return true;
                        }}
                        grid={true}
                        initialValues={{ message: record?.message }}
                      >
                        <ProForm.Group>
                          <ProFormText
                            name="message"
                            label="拒绝原因"
                            placeholder="请输入拒绝原因"
                            colProps={{ span: 24 }}
                            rules={[
                              { required: true, message: '请输入拒绝原因' },
                            ]}
                          />
                        </ProForm.Group>
                      </ModalForm>,
                      <Button
                        key="edit"
                        type="primary"
                        onClick={() => {
                          editformRef.current?.setFieldsValue({
                            sumbitType: '提交管理员审核',
                          });
                          props.form?.submit();
                        }}
                      >
                        提交管理员审核
                      </Button>,
                    ];
                  } else if (optionName === '查看') {
                    return false;
                  } else if (optionName === '修改') {
                    return doms;
                  }
                },
              }}
            >
              <ProForm.Group>
                <ProFormText width="xs" name="id" hidden />
                <ProFormText width="xs" name="seq" hidden />
                <ProFormText name="sumbitType" hidden />
                <ProFormDatePicker.Year
                  name="year"
                  label="年份"
                  colProps={{ span: 4 }}
                  hidden={localStorage.getItem('identity') !== '管理员'}
                  disabled={optionName === '查看'}
                />
                <ProFormText
                  name="meetName"
                  label="会议名称"
                  colProps={{ span: 8 }}
                  disabled={optionName === '查看'}
                />
                <ProFormText
                  name="meetLeader"
                  label="会议主席"
                  colProps={{
                    span: localStorage.getItem('identity') !== '管理员' ? 8 : 4,
                  }}
                  disabled={optionName === '查看'}
                />
                <ProFormText
                  name="meetImpleLeader"
                  label="会议执行主席"
                  colProps={{ span: 4 }}
                  disabled={optionName === '查看'}
                />
                <ProFormSelect
                  name="holdType"
                  label="举办类型"
                  options={[
                    { label: '主办', value: '主办' },
                    { label: '承办', value: '承办' },
                  ]}
                  colProps={{ span: 4 }}
                  disabled={optionName === '查看'}
                />
                <ProFormSelect
                  name="meetType"
                  label="会议类型"
                  options={[
                    { label: '全球性', value: '全球性' },
                    { label: '区域性', value: '区域性' },
                    { label: '双边性', value: '双边性' },
                    { label: '全国性', value: '全国性' },
                  ]}
                  colProps={{ span: 4 }}
                  disabled={optionName === '查看'}
                />
                <ProFormDigit
                  name="peopleCount"
                  label="参会人数"
                  colProps={{ span: 8 }}
                  disabled={optionName === '查看'}
                />
                <ProFormDatePicker
                  name="startTime"
                  label="会议日期"
                  colProps={{ span: 12 }}
                  disabled={optionName === '查看'}
                />
                {/* <ProFormDatePicker
              name="endTime"
              label="结束时间"
              colProps={{ span: 6 }}
            /> */}
              </ProForm.Group>
              <ProForm.Group title="会议地点">
                <ProFormSelect
                  name="meetPlace"
                  label="国别"
                  options={[
                    { label: '国内', value: '国内' },
                    { label: '国外', value: '国外' },
                  ]}
                  // options={getLike.countryType.run().data}
                  // request={async () => {
                  //   var temp: any = [];
                  //   await getLike.countryType.run({field:"countryType"}).then((data: any) => { temp = data })
                  //   return temp
                  // }}
                  fieldProps={{
                    onChange: (e) => {
                      editformRef.current?.setFieldsValue({ country: null });
                      getLike.run({ field: 'country', level: e });
                    },
                  }}
                  colProps={{ span: 6 }}
                  disabled={optionName === '查看'}
                />

                <ProFormDependency name={['meetPlace']}>
                  {({ meetPlace }) => {
                    return (
                      <>
                        <ProFormSelect.SearchSelect
                          name="country"
                          label="国家"
                          mode="single"
                          fieldProps={{
                            labelInValue: false,
                            onChange: (e: any) => {
                              //改变国家时清空省市
                              editformRef.current?.setFieldsValue({
                                province: null,
                                city: null,
                              });
                              if (e === '中国') {
                                getProvince.run({ field: 'PROVINCE', key: '' });
                              }
                            },
                          }}
                          rules={[
                            {
                              required: meetPlace === '国外',
                              message: '请输入会议地点',
                            },
                          ]}
                          options={getLike.data}
                          colProps={{ span: 6 }}
                          disabled={optionName === '查看'}
                        />
                        <ProFormSelect.SearchSelect
                          mode="single"
                          fieldProps={{
                            labelInValue: false,
                            onChange: (e: any) => {
                              console.log(e);
                              //改变省时清空市
                              formRef.current?.setFieldsValue({
                                city: null,
                              });
                              getCity.run({ field: 'CITY', level: e, key: '' });
                            },
                            options: getProvince?.data,
                          }}
                          name="province"
                          label="省"
                          colProps={{ span: 6 }}
                          rules={[
                            {
                              required: meetPlace === '国内',
                              message: '请输入省份',
                            },
                          ]}
                          hidden={meetPlace != '国内'}
                          disabled={optionName === '查看'}
                        />
                        <ProFormSelect.SearchSelect
                          mode="single"
                          fieldProps={{ labelInValue: false }}
                          options={getCity.data}
                          name="city"
                          label="市"
                          colProps={{ span: 6 }}
                          rules={[
                            {
                              required: meetPlace === '国内',
                              message: '请输入城市',
                            },
                          ]}
                          hidden={meetPlace != '国内'}
                          disabled={optionName === '查看'}
                        />
                      </>
                    );
                  }}
                </ProFormDependency>

                <ProFormDatePicker width="sm" name="annexPath" hidden />
                <ProFormText
                  name="reportLink"
                  label="报道链接"
                  colProps={{ span: 24 }}
                  disabled={optionName === '查看'}
                />
                <ProFormTextArea
                  name="meetingContent"
                  label="会议内容"
                  placeholder="请输入名称"
                  fieldProps={{
                    rows: 5,
                    placeholder: '最大长度为500',
                    maxLength: 500,
                  }}
                  disabled={optionName === '查看'}
                />
                <Upload {...props}>
                  <Button
                    icon={<UploadOutlined />}
                    type="link"
                    style={{ marginTop: 30 }}
                    disabled={optionName === '查看'}
                  >
                    上传材料（上传会议照片，以会议名称命名）
                  </Button>
                </Upload>
              </ProForm.Group>
            </ModalForm>
            <Button
              size="small"
              type="link"
              key="agree"
              hidden={singleRefuseShow}
              disabled={singleRefuseDisabled}
              onClick={() => {
                updateStatus
                  .run({
                    tableName: 'HOST_UNDER_MEETING',
                    ids: [record.id],
                    status: 2, //审核通过
                    tab: tabKey,
                  })
                  .then(() => {
                    message.success('操作成功');
                    findAllHostUnderMeeting.run({ auth: authAdapter(tabKey) });
                  });
              }}
            >
              同意
            </Button>
            <ModalForm
              title="拒绝"
              trigger={
                <Button
                  size="small"
                  type="link"
                  hidden={singleRefuseShow}
                  disabled={singleRefuseDisabled}
                >
                  拒绝
                </Button>
              }
              autoFocusFirstInput
              modalProps={{
                onCancel: () => console.log('run'),
                destroyOnClose: true,
              }}
              submitTimeout={2000}
              onFinish={async (values) => {
                console.log(values);
                updateStatus
                  .run({
                    tableName: 'HOST_UNDER_MEETING',
                    ids: [record.id],
                    status: 3, //拒绝
                    message: values.message,
                    tab: tabKey,
                  })
                  .then(() => {
                    message.success('操作成功');
                    findAllHostUnderMeeting.run({ auth: authAdapter(tabKey) });
                  });
                return true;
              }}
              grid={true}
              initialValues={{ message: record.message }}
            >
              <ProForm.Group>
                <ProFormText
                  name="message"
                  label="拒绝原因"
                  placeholder="请输入拒绝原因"
                  colProps={{ span: 24 }}
                  rules={[{ required: true, message: '请输入拒绝原因' }]}
                />
              </ProForm.Group>
            </ModalForm>

            <Popconfirm
              key={'2'}
              title="确定删除吗？"
              onConfirm={() => confirm(record)}
              onCancel={() => cancel}
              okText="确定"
              cancelText="取消"
            >
              <Button type="link" disabled={deleteHidden} size="small">
                删除
              </Button>
            </Popconfirm>
          </Space>
        );
      },
    },
  ];
  const authAdapter = (key: any) => {
    let authTemp: any = 0;
    if (key === '个人视角') {
      authTemp = 0;
    }
    if (key === '子方向视角') {
      authTemp = 1;
    }
    if (key === '方向视角') {
      authTemp = 2;
    }
    if (key === '管理员视角') {
      authTemp = 3;
    }
    return authTemp;
  };
  const Refresh = () => {
    findAllHostUnderMeeting.run();
  };
  return (
    <PageContainer
      tabList={ReturnTablist()}
      header={{
        title: null,
        breadcrumb: (
          <Breadcrumb>
            <Breadcrumb.Item>合作交流</Breadcrumb.Item>
            <Breadcrumb.Item>主办承办会议</Breadcrumb.Item>
          </Breadcrumb>
        ),
      }}
      onTabChange={(key: any) => {
        setTabKey(key);
        findAllHostUnderMeeting.run({ auth: authAdapter(key) });
        ref.current?.resetFields();
      }}

    >
      <ProTable
        columns={columns}
        dataSource={findAllHostUnderMeeting?.data}
        rowKey="id"
        pagination={{
          showQuickJumper: true,
          pageSize: 10,
        }}
        onSubmit={(e: any) => {
          findAllHostUnderMeeting.run({ ...e, auth: authAdapter(tabKey) });
        }}
        search={{ labelWidth: 'auto' }}
        onReset={() => {
          findAllHostUnderMeeting.run({ auth: authAdapter(tabKey) });
        }}
        loading={findAllHostUnderMeeting.loading}
        dateFormatter="string"
        headerTitle="会议列表"
        scroll={{ x: 'calc(1300px + 50%)' }}
        options={false}
        formRef={ref}
        toolBarRender={() => [
          <ImportExcel
            tableName={'HOST_UNDER_MEETING'}
            Refresh={Refresh}
          />,
          <Button
            type="primary"
            onClick={() => {
              window.open(
                'http://10.1.40.84:9993/file/model/HOST_UNDER_MEETING_模板.xlsx ',
              );
            }}
          >
            下载模版
          </Button>,
          <div>
            {tabKey === '管理员视角' || tabKey === '子方向视角' ? (
              <Button
                type="primary"
                icon={<FileSearchOutlined />}
                onClick={() => {
                  toggle();
                }}
              >
                批量审核
              </Button>
            ) : null}
          </div>,
          <ModalForm
            title="新增会议"
            trigger={
              <Button key="primary" type="primary">
                新增会议
              </Button>
            }
            autoFocusFirstInput
            modalProps={{
              onCancel: () => console.log('run'),
              destroyOnClose: true,
            }}
            submitTimeout={2000}
            onFinish={async (values) => {
              if (values.annexPath && values.annexPath !== '') {
                insertHostUnderMeeting.run(values).then(() => {
                  findAllHostUnderMeeting.run({ auth: authAdapter(tabKey) });
                  message.info('添加成功！');
                });
              } else {
                message.error('请上传文件');
                return false;
              }
              return true;
            }}
            key="1"
            formRef={formRef}
            grid={true}
          >
            <ProForm.Group>
              <ProFormDatePicker.Year
                name="year"
                label="年份"
                colProps={{ span: 4 }}
                hidden={localStorage.getItem('identity') !== '管理员'}
              />
              <ProFormText
                name="meetName"
                label="会议名称"
                colProps={{ span: 8 }}
                rules={[{ required: true, message: '请输入会议名称' }]}
              />
              <ProFormText
                name="meetLeader"
                label="会议主席"
                colProps={{
                  span: localStorage.getItem('identity') !== '管理员' ? 8 : 4,
                }}
                rules={[{ required: true, message: '请输入会议执行主席' }]}
              />
              <ProFormText
                name="meetImpleLeader"
                label="会议执行主席"
                colProps={{ span: 4 }}
                // rules={[{ required: true, message: '请输入会议执行主席' }]}
              />
              <ProFormSelect
                name="holdType"
                label="举办类型"
                options={[
                  { label: '主办', value: '主办' },
                  { label: '承办', value: '承办' },
                ]}
                colProps={{ span: 4 }}
                rules={[{ required: true, message: '请输入举办类型' }]}
              />
              <ProFormSelect
                name="meetType"
                label="会议类型"
                options={[
                  { label: '全球性', value: '全球性' },
                  { label: '区域性', value: '区域性' },
                  { label: '双边性', value: '双边性' },
                  { label: '全国性', value: '全国性' },
                ]}
                colProps={{ span: 4 }}
                rules={[{ required: true, message: '请输入会议类型' }]}
              />
              <ProFormDigit
                name="peopleCount"
                label="参会人数"
                colProps={{ span: 8 }}
                rules={[{ required: true, message: '请输入参会人数' }]}
              />
              <ProFormDatePicker
                name="startTime"
                label="会议日期"
                colProps={{ span: 12 }}
                rules={[{ required: true, message: '请输入会议日期' }]}
              />
              {/* <ProFormDatePicker
                name="endTime"
                label="结束时间"
                colProps={{ span: 6 }}
              /> */}
            </ProForm.Group>
            <ProFormSelect
              name="meetPlace"
              label="会议地点"
              options={[
                { label: '国内', value: '国内' },
                { label: '国外', value: '国外' },
              ]}
              rules={[{ required: true, message: '请输入会议地点' }]}
              // options={getLike.countryType.run().data}
              // request={async () => {
              //   var temp: any = [];
              //   await getLike.countryType.run({field:"countryType"}).then((data: any) => { temp = data })
              //   return temp
              // }}
              fieldProps={{
                onChange: (e) => {
                  formRef.current?.setFieldsValue({ country: null });
                  getLike.run({ field: 'country', level: e });
                },
              }}
              colProps={{ span: 6 }}
            />
            <ProFormDependency name={['meetPlace']}>
              {({ meetPlace }) => {
                return (
                  <>
                    <ProFormSelect.SearchSelect
                      name="country"
                      label="国家"
                      mode="single"
                      fieldProps={{
                        labelInValue: false,
                        onChange: (e: any) => {
                          console.log(e);
                          //改变国家时清空省市
                          formRef.current?.setFieldsValue({
                            province: null,
                            city: null,
                          });
                          if (e === '中国') {
                            getProvince.run({ field: 'PROVINCE', key: '' });
                          }
                        },
                      }}
                      options={getLike.data}
                      colProps={{ span: 6 }}
                      rules={[
                        {
                          required: meetPlace === '国外',
                          message: '请输入会议地点',
                        },
                      ]}
                    />
                    <ProFormSelect.SearchSelect
                      name="province"
                      label="省"
                      mode="single"
                      fieldProps={{
                        labelInValue: false,
                        onChange: (e: any) => {
                          console.log(e);
                          //改变省时清空市
                          formRef.current?.setFieldsValue({
                            city: null,
                          });
                          getCity.run({ field: 'CITY', level: e, key: '' });
                        },
                        options: getProvince?.data,
                      }}
                      colProps={{ span: 6 }}
                      rules={[
                        {
                          required: meetPlace === '国内',
                          message: '请输入省份',
                        },
                      ]}
                      hidden={meetPlace != '国内'}
                    />
                    <ProFormSelect.SearchSelect
                      name="city"
                      label="市"
                      mode="single"
                      fieldProps={{ labelInValue: false }}
                      options={getCity.data}
                      colProps={{ span: 6 }}
                      rules={[
                        {
                          required: meetPlace === '国内',
                          message: '请输入城市',
                        },
                      ]}
                      hidden={meetPlace != '国内'}
                    />
                  </>
                );
              }}
            </ProFormDependency>

            <ProFormDatePicker width="sm" name="annexPath" hidden />
            <ProFormText
              name="reportLink"
              label="报道链接"
              colProps={{ span: 24 }}
            />
            <ProFormTextArea
              name="meetingContent"
              label="会议内容"
              placeholder="请输入名称"
              fieldProps={{
                rows: 5,
                placeholder: '最大长度为500',
                maxLength: 500,
              }}
            />
            <Upload {...props}>
              <Button
                icon={<UploadOutlined />}
                type="link"
                style={{ marginTop: 30 }}
              >
                上传材料（上传会议照片，以会议名称命名）
              </Button>
            </Upload>
            {/* </ProForm.Group> */}
          </ModalForm>,
        ]}
        rowSelection={
          selectRow
            ? {
                selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
              }
            : false
        }
        tableAlertOptionRender={({
          selectedRowKeys,
          selectedRows,
          onCleanSelected,
        }) => (
          <Space size={16}>
            <a style={{ marginLeft: 8 }} onClick={onCleanSelected}>
              取消选择
            </a>
            <a
              onClick={() => {
                updateStatus
                  .run({
                    tableName: 'HOST_UNDER_MEETING',
                    ids: selectedRowKeys,
                    status: 2, //审核通过
                  })
                  .then(() => {
                    message.success('操作成功');
                    onCleanSelected();
                    toggle();
                    findAllHostUnderMeeting.run();
                  });
              }}
            >
              审核通过
            </a>
            <a
              onClick={() => {
                updateStatus
                  .run({
                    tableName: 'HOST_UNDER_MEETING',
                    ids: selectedRowKeys,
                    status: 3, //拒绝
                  })
                  .then(() => {
                    message.success('操作成功');
                    onCleanSelected();
                    toggle();
                    findAllHostUnderMeeting.run();
                  });
              }}
            >
              拒绝
            </a>
          </Space>
        )}
      />
    </PageContainer>
  );
};
